$(function(){
  $('#uploadForm input[name=file]').change(function(){
    var fileName = $('#uploadForm input[name=file]').val().split('\\').pop();
    $('#uploadForm input[name=key]').val(fileName);
    var formData = new FormData($('#uploadForm')[0]);
    $.ajax({
        url: 'http://upload.qiniu.com/',
        type: 'POST',
        cache: false,
        data: formData,
        processData: false,
        contentType: false
    }).done(function(res) {
        var text = $('textarea').val();
        var fileText = '![](http://kaychen.u.qiniudn.com/'+fileName+')';
        $('textarea').val(text+fileText);
    }).fail(function(res) {});
  });
});
